package com.klb.dao.impl;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.klb.base.DaoBase;
import com.klb.dao.AdminDao;
import com.klb.model.BbsAdmin;
import com.klb.tools.Tools;

/**
 * Created by fujia on 2016/7/2.
 */
public class AdminDaoImpl extends DaoBase implements AdminDao {
    

    @Override
    public BbsAdmin getAdminByUsername(String username) {
    	BbsAdmin admin = null;
    	
        if (!Tools.objectIsNullOrNot(username)){
            Session session = this.hibernateSessionFactory.getCurrentSession();
            Transaction tx = null;
            String sql = "from BbsAdmin admin where admin.username = :username";

            try{
                tx = session.beginTransaction();

                Query query = session.createQuery(sql);
                query.setParameter("username", username);

                admin = (BbsAdmin) query.uniqueResult();

                tx.commit();

            } catch (Exception e){
                tx.rollback();
                e.printStackTrace();
            }
        }

        return admin;
    }
}
